package com.szqhyxj.youxiangju.biz.partnerHome.home.fragment.partnerequipment;

import com.szqhyxj.youxiangju.sys.BaseResult;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/11/20.
 */

public class PartnerEquipmentPaymentPresenter implements PartnerEquipmentPaymentContract.Presenter {
    PartnerEquipmentPaymentContract.View view;

    public PartnerEquipmentPaymentPresenter(PartnerEquipmentPaymentContract.View view) {
        this.view = view;
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void init() {
        PartnerEquipmentPaymentModel.getpartnerHomeInfo()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<BaseResult<PartnerEquipmentPaymentModel.PartnerequipmentEntity>>() {
                    @Override
                    public void accept(BaseResult<PartnerEquipmentPaymentModel.PartnerequipmentEntity> partnerequipmentEntityBaseResult) throws Exception {

                        if (partnerequipmentEntityBaseResult.businessLogicSuccess()) {

                          view.showActivationReward(partnerequipmentEntityBaseResult.getData().getMonthActivateRewards()+"");
                          view.showEquipmentPaymentInfo(partnerequipmentEntityBaseResult.getData().getProxyEntity());
                          view.showEquipmentReceiptInfo(partnerequipmentEntityBaseResult.getData().getQuickEntity());

                        } else {

                            view.showToast(partnerequipmentEntityBaseResult.getData().toString());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        view.showToast(throwable.getMessage());

                    }
                });
    }

    @Override
    public void setPaymentDetails() {
        view.navToPaymentDetails();
    }

    @Override
    public void setReceiptDetails() {
        view.navToReceiptDetails();

    }

    @Override
    public void setRewardDetails() {
        view.navToRewardDetails();

    }
}
